<template>
  <view
    class="order-item"
    @click="$emit('click')"
  >
    <view class="header">
      <v-icon
        size="36rpx"
        src="@/static/icons/cart-merchant.svg"
      />
      <view class="merchant-name">
        <view class="name-text">
          {{ complaint.store_name }}
        </view>
      </view>
      <view
        class="status"
        :class="{
          highlight:
            status === '您已投诉，待商家处理' || status === '商家已回复'
        }"
      >
        {{ status }}
      </view>
    </view>
    <complaint-product
      v-if="product"
      :product="product"
    />
    <view class="info">
      {{ `投诉: ${reasons[complaint.reason]}` }}
    </view>
    <view class="summary">
      <view class="summary-label">
        实付
      </view>
      <v-price
        :price="price"
        size="32rpx"
        color="#333333"
      />
    </view>
  </view>
</template>

<script setup lang="ts">
import ComplaintProduct from './complaint-product.vue';

const props = defineProps<{
  complaint: OrderComplaintProgressVO;
}>();

defineEmits<{
  click: [];
}>();

const complaint = toRef(props, 'complaint');
const status = computed(() => {
  switch (true) {
    case complaint.value.status === 'PENDING':
      return '您已投诉，待商家处理';
    case complaint.value.status === 'PROCESSING':
      return '商家已回复';
    case complaint.value.status === 'PROCESSED':
      return '商家已处理';
    case complaint.value.status === 'CLOSE':
    case complaint.value.status === 'CLOSE_CUSTOMER_TIMEOUT':
    case complaint.value.status === 'FINISH' && !complaint.value.accept_flag:
      return '投诉已关闭';
    case complaint.value.status === 'FINISH':
      return '投诉已完成';
    case complaint.value.status === 'REVOCATION':
      return '投诉已撤回';
    default:
      return '';
  }
});
const product = computed(() => props.complaint.order_detail_list?.[0]);
const price = computed(() => {
  if (!product.value) return undefined;
  const price = product.value.sell_price;
  const count = product.value.quantity;
  const discount = product.value.discount_price ?? 0;
  const val = price * count - discount;
  return Math.max(val, 0);
});

const reasons = {
  UNSHIPPED: '超时未发货',
  LESS_SHIPPED: '少发',
  WRONG_SHIPPED: '错发',
  SHAM_SHIPPED: '虚假发货',
  DISCREPANCY_DESCRIPTION: '描述不符',
  DAMAGED: '商品破损',
  QUALITY_PROBLEM: '质量问题',
  CUSTOMER_SERVICE_NOT_REPLY: '客服不回复',
  CUSTOMER_SERVICE_NOT_PROCESS: '客服不处理',
  ABNORMAL_ATTITUDE: '态度异常',
  MINI_PROGRAM_EXPERIENCE: '小程序体验',
  ALIPAY_REPORT: '支付宝举报'
};
</script>

<style lang="scss" scoped>
.order-item {
  padding: calc(28rpx - 2px) calc(24rpx - 2px);
  margin: 0 24rpx 24rpx;
  background-color: white;
  border-radius: 16rpx;
  border: 2px solid white;
  display: flex;
  flex-direction: column;
  gap: 28rpx;
  .header {
    height: 40rpx;
    display: flex;
    align-items: center;
    gap: 20rpx;
    .merchant-name {
      flex: 1;
      min-width: 0;
      display: flex;
      align-items: center;
      .name-text {
        font-size: 28rpx;
        font-weight: bold;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        word-break: break-all;
      }
    }
    .status {
      line-height: 36rpx;
      color: #999999;
      &.highlight {
        color: #ff2f3b;
      }
    }
  }
  .info {
    font-weight: bold;
    background-color: #f5f6fa;
    border-radius: 4rpx;
    line-height: 60rpx;
    padding: 0 24rpx;
  }
  .summary {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8rpx;
    .summary-label {
      font-size: 28rpx;
    }
  }
  .footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 30rpx;
    .aftersales-status {
      margin-right: auto;
      color: #ff2f3b;
      padding: 12rpx 0;
    }
  }
}
</style>
